package cn.iocoder.yudao.module.shop.footprint.service;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.business.basic.dao.query.CoreQueryWrapper;
import cn.iocoder.yudao.framework.business.basic.pojo.vo.UserSimpleVO;
import cn.iocoder.yudao.framework.business.basic.service.impl.MemberScopeService;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.api.member.user.MemberUserApi;
import cn.iocoder.yudao.module.shop.footprint.dal.dataobject.ShopFootprintDO;
import cn.iocoder.yudao.module.shop.footprint.dal.mysql.ShopFootprintMapper;
import cn.iocoder.yudao.module.shop.footprint.vo.AdminShopFootprintQueryDTO;
import cn.iocoder.yudao.module.shop.footprint.vo.AdminShopFootprintVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.Collection;
import java.util.Map;

/**
 * 店铺浏览记录 Service 实现类
 *
 * @author 山野羡民
 */
@Service
@Validated
public class AdminShopFootprintServiceImpl extends MemberScopeService<ShopFootprintDO, AdminShopFootprintVO, AdminShopFootprintQueryDTO> implements AdminShopFootprintService {
    @Resource
    private ShopFootprintMapper shopFootprintMapper;

    @Resource
    private MemberUserApi memberUserApi;

    @Override
    protected ShopFootprintMapper getInjectedMapper() {
        return shopFootprintMapper;
    }

    @Override
    public PageResult<AdminShopFootprintVO> getPage(Integer current, Integer size, @Nonnull AdminShopFootprintQueryDTO param) {
        QueryWrapper<ShopFootprintDO> wrapper = new CoreQueryWrapper<>();
        wrapper.eq("user_id", param.getUserId());
        wrapper.eq("recycled", false);
        PageResult<ShopFootprintDO> page = shopFootprintMapper.selectPage(current, size, wrapper);
        if (CollUtil.isEmpty(page.getList())) {
            return PageResult.empty();
        }
        return new PageResult<>(convertToViewObject(page.getList()), page.getTotal());
    }

    @Nonnull
    @Override
    protected Map<Long, UserSimpleVO> getUserSimpleMap(Collection<Long> shopIds) {
        return memberUserApi.getUserSimpleMap(shopIds);
    }

}
